package com.flowplan.websocket.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 协作消息DTO
 * 用于WebSocket实时协作消息传递
 */
@Data
public class CollaborationMessage {
    
    /**
     * 消息类型
     * DATA_CHANGE: 数据变更
     * CONFLICT: 冲突检测
     * LOCK_REQUEST: 锁定请求
     * LOCK_RESPONSE: 锁定响应
     * ERROR: 错误消息
     */
    private String messageType;
    
    /**
     * 操作类型
     * CREATE: 创建
     * UPDATE: 更新
     * DELETE: 删除
     * MOVE: 移动
     * CONFLICT_DETECTED: 冲突检测
     */
    private String operationType;
    
    /**
     * 用户ID
     */
    private String userId;
    
    /**
     * 项目ID
     */
    private Long projectId;
    
    /**
     * 资源ID (任务ID、Excel ID等)
     */
    private String resourceId;
    
    /**
     * 消息数据 (JSON格式)
     */
    private String data;
    
    /**
     * 版本号 (用于冲突检测)
     */
    private Long version;
    
    /**
     * 时间戳
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime timestamp;
    
    /**
     * 消息ID (用于追踪)
     */
    private String messageId;
    
    /**
     * 附加信息
     */
    private String metadata;
    
    public CollaborationMessage() {
        this.timestamp = LocalDateTime.now();
    }
    
    public CollaborationMessage(String messageType, String operationType, String userId, Long projectId) {
        this();
        this.messageType = messageType;
        this.operationType = operationType;
        this.userId = userId;
        this.projectId = projectId;
    }
}